#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <math.h>
using namespace std;
const int N = 1e8+10;
const int Nsub = 1e8+10;
bool IsPrime[N];
int Prime[Nsub];
int main()
{
	//初始化
	memset(IsPrime, 1, sizeof(bool) * N);
	IsPrime[0] = false;
	IsPrime[1] = false;
	int n = 0, Prime_cnt = 1, q = 0;
	scanf("%d%d", &n, &q);
	for (int i = 3; i*i <= n ; i += 2)
	{
		if(IsPrime[i])
		{
			for (int j = i * i; j <= n; j += 2 * i)
			{
				IsPrime[j] = false;
			}
		}
	}
	Prime[0] = 2;
	for (int i = 3; i <= n; i += 2)
	{
		if (IsPrime[i])
		{
			Prime[Prime_cnt] = i;
			Prime_cnt++;
		}
	}
	/*for (int i = 0; i < Prime_cnt; i++)
	{
		printf("%d\n", Prime[i]);
	}*/
	while (q--)
	{
		int rank;
		scanf("%d", &rank);
		printf("%d\n", Prime[rank - 1]);
	}
	return 0;
}